package com.demo.config;

import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.expression.OAuth2WebSecurityExpressionHandler;
import org.springframework.security.web.FilterInvocation;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * SecurityExpressionHandler
 *
 * @author liujin
 * @date 2020/12/7 23:59
 */
@Component
public class SecurityExpressionHandler extends OAuth2WebSecurityExpressionHandler {

    @Resource
    private AccessServiceImpl accessService;

    @Override
    protected StandardEvaluationContext createEvaluationContextInternal(Authentication authentication, FilterInvocation invocation) {
        StandardEvaluationContext sec = super.createEvaluationContextInternal(authentication, invocation);
        sec.setVariable("accessService", accessService);
        return sec;
    }
}
